﻿using MyToDo.Common.Models;
using MyToDo.Common.Prism;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyToDo.ViewModels
{
    public class SettingViewModel : BindableBase
    {

        public SettingViewModel(IRegionManager regionManager)
        {
            MenuBars = new ObservableCollection<MenuBar>();
            NavigateCommand = new DelegateCommand<MenuBar>(Navigate);
            this.regionManager = regionManager;
            CreateMenuBar();
        }



        /// <summary>
        /// 路由导航功能
        /// </summary>
        /// <param name="obj">路由菜单</param>
        private void Navigate(MenuBar obj)
        {
            //加入判断，如果是空对象或者命名空间为空则跳出
            if (obj == null || string.IsNullOrEmpty(obj.NameSpace))
            {
                return;
            }
            regionManager.Regions[PrismManager.SettingViewRegionName].RequestNavigate(obj.NameSpace);



        }

        /// <summary>
        /// 引入Prism路由管理
        /// </summary>
        private readonly IRegionManager regionManager;


        /// <summary>
        /// 用于导航
        /// </summary>
        public DelegateCommand<MenuBar> NavigateCommand { get; set; }

        private ObservableCollection<MenuBar> menuBars;

        public ObservableCollection<MenuBar> MenuBars
        {
            get { return menuBars; }
            set { menuBars = value; RaisePropertyChanged(); }
        } //动态更新列表

        void CreateMenuBar()
        {
            MenuBars.Add(new MenuBar { Icon = "Palette", Title = "个性化", NameSpace = "SkinView" });
            MenuBars.Add(new MenuBar { Icon = "CogOutline", Title = "系统设置", NameSpace = "ToDoView" });
            MenuBars.Add(new MenuBar { Icon = "InformationOutline", Title = "关于更多", NameSpace = "AboutView" });
        }
    }
}
